﻿using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using WebApi.Common;
using WebApi.Common.MiddleWare;
using WXQ.BusinessCore.opLogManager;
using WXQ.Enties.CommonObj;
using WXQ.InOutPutEntites.Input;
using WXQ.InOutPutEntites.Input.LogManage.NLog;
using WXQ.InOutPutEntites.Output;

namespace WebApi.Controllers.LogManage
{
    /// <summary>
    /// 调试日志
    /// </summary>
    [Route("Api/LogManage/NLog")]
    [Authorize]
    public class NLogController : BaseController
    {
        /// <summary>
        /// 查找调试日志
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("GetNLogList")]
        [Log]
        public JsonResult GetNLogList([FromBody] GetNLogListInput model)
        {
            var result = new ResponseResult();

            var op = new NLogOp();

            var pagemodel = model.Page.Adapt<PageInput, PageModel>();
            var rv = op.GetNLogList(model.application, model.level, model.message, model.bgDt, model.endDt,
                model.Logger, model.CallSite, pagemodel);

            if (rv == null)
            {
                result.Code = ResponseResultMessageDefine.OpLost;
                result.Errors.Add(ResponseResultMessageDefine.OpLostMessage);
            }
            else
            {
                result.Data = rv;
            }

            return Json(result);
        }

        /// <summary>
        /// 删除调试日志
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("Delete")]
        [Log]
        public JsonResult Delete([FromBody] NLogDeleteInput model)
        {
            var result = new ResponseResult();

            var op = new NLogOp();

            var rv = op.Delete(model.application, model.level, model.message, model.bgDt, model.endDt, model.Logger,
                model.CallSite);

            if (!rv)
            {
                result.Code = ResponseResultMessageDefine.OpLost;
                result.Errors.Add(ResponseResultMessageDefine.OpLostMessage);
            }
            else
            {
                result.Data = rv;
            }

            return Json(result);
        }
    }
}